<?php

namespace support;

class FileStore
{
    public function upload($request, $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'])
    {
        $file = $request->file('file');

        $extension = $file->getUploadExtension();

        if (!in_array($extension, $allowedExtensions)) {
            return err_rsp('不正确的文件扩展');
        }

        $relativePath = '/userUpload/' . microtime(true) * 1000 . '.' . $extension;
        $file->move(public_path() . $relativePath);

        return getenv('APP_URL') . $relativePath;
    }
}